package com.yuw.model.impl;

import com.yuw.bean.userinfo.UserInfoBean;
import com.yuw.dao.DBProvider;
import com.yuw.model.IModelUserinfo;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ModelUserinfoImpl implements IModelUserinfo {
    // 依赖注入dao层
    @Autowired
    private DBProvider dbProvider;

    @Override
    public boolean doLogin(UserInfoBean userInfoBean) {
        System.out.println("调用了IModelUserinfo的实现类。。。。");
        // 登录业务逻辑验证处理
        // 登录查询的sql语句
        String strSql = "SELECT * FROM userinfo WHERE userName = ? AND userPsw = ?";
        // 调用dao层进行数据库操作
        List<UserInfoBean> lstUsers = dbProvider.
                query(strSql, new BeanListHandler<>(UserInfoBean.class), new Object[]{userInfoBean.getUserName(), userInfoBean.getUserPsw()});
        // 返回结果
        return lstUsers != null && lstUsers.size() > 0;

    }
}
